var express = require('express');
var router = express.Router();
var sqlQuery = require('../../lcMsql')

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.render('admin/users/userlist2')
});

router.get('/api/userlist',async (req,res)=>{
  let page = req.query.page;
  let limitNum = req.query.limit;
  console.log(page,limitNum)
  let sqlStr = 'select `user`.id, `user`.username, `user`.imgheader, `user`.roleid, role.rolename from user LEFT JOIN role on `user`.roleid = role.id limit ?,?'

  let arr = [(page-1)*limitNum,1*limitNum]
  console.log(arr)
  let result = await sqlQuery(sqlStr,arr)

  //获取总数
  let sqlStrNum = 'select count(id) as usernum from user';
  let resNum = await sqlQuery(sqlStrNum)
  let count = resNum[0].usernum;

  let options = {
      "code":0,
      "msg":'',
      "count": count,
      "data": Array.from(result)
  }
  res.json(options)
})

module.exports = router;
